function [ykalman] = ex1kalman()
    load('Data/simdata.mat','t','y','ynf','ysin');
    % State = (y ydot). We only observe (y).
    % X(t+1) = F X(t) + noise(Q)
    % Y(t) = H X(t) + noise(R)

    ss = 2; % state size
    os = 1; % observation size
    F = [1 0; 0 1]; 
    H = [1 0];
    Q = 0.1*eye(ss);
    R = 1*eye(os);
    initx = [0 0]';
    inity = 1*eye(ss);

    %[xfilt, Vfilt, VVfilt, loglik] = kalman_filter(y, F, H, Q, R, initx, inity);
    ykalman = kalman_smoother(y, F, H, Q, R, initx, inity);

    % dfilt = x(1,:) - xfilt(1,:);
    % mse_filt = sqrt(sum(sum(dfilt.^2)))

%     dsmooth = x(1,:) - xsmooth(1,:);
%     mse_smooth = sqrt(sum(sum(dsmooth.^2)))
    ykalman = ykalman(1,:);

    figure
    plot(t,ynf,'r',t,ynf+ysin,'m',t,ykalman,'b');
    legend('ynf', 'ynf+ysin', 'ykalman')
    title('Kalman');
    
    save('Data/kalman.mat','ykalman');
end

